﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class Module_Menu : PanelControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    ChanelBusiness cb = new ChanelBusiness();
    public string viewMenu()
    {
        ArrayList items = cb.showMenu();
        ArrayList itemsChild = new ArrayList();
        string tmp = "";
        if (items.Count > 0)
        {
            tmp = "<ul><h3>";
            for (int i = 0; i < items.Count; i++)
            {
                ChanelEntities item_i = (ChanelEntities)items[i];
                for (int j = 0; j < items.Count; j++)
                {
                    ChanelEntities item_j=(ChanelEntities)items[j];
                    if (item_j._channelParentID == item_i._channelID)
                        itemsChild.Add(item_j);
                    else
                        item_j = null;
                }
                if (itemsChild.Count > 0)
                {
                    tmp += "<li><a href=\"" + item_i._channelLink + "?cid=" + item_i._channelID + "\">" + item_i._channelName + "</a><ul>";
                    for (int k = 0; k < itemsChild.Count; k++)
                    {
                        ChanelEntities item_k = (ChanelEntities)itemsChild[k];
                        tmp += "<li><a href=\"" + item_k._channelLink + "?cid=" + item_k._channelID + "\">" + item_k._channelName + "</a></li>";
                    }
                    tmp += "</ul></li>";
                    itemsChild.Clear();
                }
                else
                {
                    bool check = true;
                    for (int q = 0; q < items.Count; q++)
                    {
                        ChanelEntities item_q = (ChanelEntities)items[q];
                        if (item_i._channelParentID == item_q._channelID)
                        {
                            check = false;
                            break;
                        }
                    }
                    if (check)
                        tmp += "<li><a href=\"" + item_i._channelLink + "?cid=" + item_i._channelID + "\">" + item_i._channelName + "</a></li>";
                }
            }
            tmp += "</ul>";
        }
        return tmp;
    }
}